<ClientManagerView:EventResourceDictionary x:Class="FacebookClient.FriendSummaryEventResourceDictionary"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls"
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    xmlns:ClientManager="clr-namespace:ClientManager"
    xmlns:ClientManagerData="clr-namespace:ClientManager.Data"
    xmlns:ClientManagerView="clr-namespace:ClientManager.View"
    xmlns:TextSelection="clr-namespace:Microsoft.Wpf.Samples.Documents">

  <FacebookClient:ContentVisibilityConverter x:Key="ContentVisibilityConverter" />
  <FacebookClient:DateTimeToStringConverter x:Key="DateTimeConverter" />
  <FacebookClient:CityStateConverter x:Key="CityStateConverter" />
  <FacebookClient:AddConverter x:Key="AddConverter" />

  <Style x:Key="MessageTextBlockStyle" TargetType="TextBlock">
    <Setter Property="TextWrapping" Value="Wrap" />
    <Setter Property="FontFamily" Value="{DynamicResource SerifFont}" />
    <Setter Property="FontSize" Value="{DynamicResource MiddleFontSize}" />
    <Setter Property="Foreground" Value="{DynamicResource ActivityPostMessageTextBlockForeground}"/>
    <Setter Property="TextSelection:TextSelection.IsEnabled" Value="True" />
  </Style>

  <DataTemplate x:Key="FriendSummaryItemTemplate">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      <FacebookClient:FriendButton VerticalAlignment="Top" 
                                   Friend="{Binding}" 
                                   Style="{DynamicResource MediumFriendButtonStyle}" 
                                   Click="OnNavigateToContentButtonClicked" 
                                   ClientManagerView:ViewManager.NavigationContent="{Binding}" />
      <DockPanel Grid.Column="1" Margin="15,-5,5,10" VerticalAlignment="Top">
        <FacebookClient:ContactNameDisplayControl DockPanel.Dock="Top" Foreground="{DynamicResource HyperlinkForegroundBrush}" FacebookContact="{Binding}"/>
        
        <!-- Show current location, unless the sort order is by Birthdays -->
        <TextBlock DockPanel.Dock="Top"
            Margin="0,1,0,0" 
            Text="{Binding Converter={StaticResource CityStateConverter}}">
          <TextBlock.Style>
            <Style TargetType="{x:Type TextBlock}">
              <Setter Property="Visibility" Value="Visible" />
              <Setter Property="FontFamily" Value="{DynamicResource SansSerifFont}" />
              <Setter Property="FontSize" Value="{DynamicResource MiddleFontSize}" />
              <Setter Property="Foreground" Value="{DynamicResource ActivityPostMessageTextBlockForeground}"/>
              <Setter Property="TextSelection:TextSelection.IsEnabled" Value="True" />
              <Style.Triggers>
               <DataTrigger Binding="{Binding Converter={StaticResource CityStateConverter}}" Value="">
                 <Setter Property="Visibility" Value="Collapsed" />
               </DataTrigger>
               <DataTrigger Binding="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=ActiveContactSortOrder}" Value="AscendingByBirthday">
                 <Setter Property="Visibility" Value="Collapsed" />
               </DataTrigger>
               <DataTrigger Binding="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=ActiveContactSortOrder}" Value="DescendingByBirthday">
                 <Setter Property="Visibility" Value="Collapsed" />
               </DataTrigger>
              </Style.Triggers>
            </Style>
          </TextBlock.Style>
        </TextBlock>

        <TextBlock DockPanel.Dock="Top" Margin="0,1,0,0" Text="{Binding Birthday}">
          <TextBlock.Style>
            <Style TargetType="{x:Type TextBlock}">
              <Setter Property="Visibility" Value="Collapsed" />
              <Setter Property="FontFamily" Value="{DynamicResource SansSerifFont}" />
              <Setter Property="FontSize" Value="{DynamicResource MiddleFontSize}" />
              <Setter Property="Foreground" Value="{DynamicResource ActivityPostMessageTextBlockForeground}"/>
              <Setter Property="TextSelection:TextSelection.IsEnabled" Value="True" />
              <Style.Triggers>
                <DataTrigger Binding="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=ActiveContactSortOrder}" Value="AscendingByBirthday">
                  <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=ActiveContactSortOrder}" Value="DescendingByBirthday">
                  <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Birthday}" Value="">
                  <Setter Property="Visibility" Value="Collapsed" />
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </TextBlock.Style>
        </TextBlock>
        <TextBlock DockPanel.Dock="Bottom" Text="{Binding StatusMessage.Created, Converter={StaticResource DateTimeConverter}}" Margin="0,2,0,0" Style="{DynamicResource CreatedTextBlockStyle}" Visibility="{Binding StatusMessage.Message, Converter={StaticResource ContentVisibilityConverter}}" />
        
        <TextBlock Margin="0,9,0,0"
            Style="{StaticResource MessageTextBlockStyle}" 
            TextTrimming="WordEllipsis"
            Visibility="{Binding StatusMessage.Message, Converter={StaticResource ContentVisibilityConverter}}">
          <FacebookClient:HyperlinkTextContent Text="{Binding StatusMessage.Message}" FontWeight="Medium" />
        </TextBlock>

      </DockPanel>
    </Grid>
  </DataTemplate>

  <ControlTemplate TargetType="{x:Type FacebookClient:FriendSummaryControl}" x:Key="FriendSummaryTemplate">
    <Grid DataContext="{Binding ElementName=FriendsList, Path=ListPager}">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      
      <FacebookClient:SortControl Width="200" SortOrderMode="Contacts" TitleText="{Binding Path=ItemsSource.Count, StringFormat=\{0\} friends}">
        <FacebookClient:SortControl.Style>
          <Style TargetType="{x:Type FacebookClient:SortControl}">
            <Style.Triggers>
              <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FacebookClient:MainWindow}}, Path=IsInSmallMode}" Value="True">
                <Setter Property="Visibility" Value="Collapsed" />
              </DataTrigger>
            </Style.Triggers>
          </Style>
        </FacebookClient:SortControl.Style>
      </FacebookClient:SortControl>

      <FacebookClient:PaginatedItemsControl 
          x:Name="FriendsList"
          Grid.Column="1"
          Margin="20,20,5,5" 
          PaginatedItemsSource="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=Friends}" 
          ItemTemplate="{StaticResource FriendSummaryItemTemplate}"
          Background="Transparent">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <FacebookClient:AnimatingTilePanel ItemHeight="125" ItemWidth="350" Attraction="2.4" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </FacebookClient:PaginatedItemsControl>

      <Grid Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,0,5">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <RepeatButton
            Style="{DynamicResource SimpleButtonBaseStyle}"
            Grid.Column="0"
            Margin="5,1"
            Command="{Binding Path=PreviousCommand}" 
            ToolTip="Previous page">
          <Rectangle Height="25" Width="25" Fill="{DynamicResource LeftArrowToolbarDrawingBrush}"/>
        </RepeatButton>
        <TextBlock Grid.Column="1" Style="{DynamicResource ToolbarTextBlockStyle}" MinWidth="80" TextAlignment="Center">
          <TextBlock.Text>
            <MultiBinding StringFormat="{}Page {0} of {1}">
              <Binding Path="CurrentPageIndex" Converter="{StaticResource AddConverter}" ConverterParameter="1" />
              <Binding Path="PageCount" />
            </MultiBinding>
          </TextBlock.Text>
        </TextBlock>
        <RepeatButton
            Style="{DynamicResource SimpleButtonBaseStyle}"
            Grid.Column="2"
            Margin="5,1"
            Command="{Binding Path=NextCommand}" 
            ToolTip="Next page">
          <Rectangle Height="25" Width="25" Fill="{DynamicResource RightArrowToolbarDrawingBrush}"/>
        </RepeatButton>
      </Grid>
    </Grid>
  </ControlTemplate>

  <ClientManagerControls:SizeControlTemplateCollection x:Key="FriendSummaryTemplateCollection">
    <ClientManagerControls:SizeControlTemplate Template="{StaticResource FriendSummaryTemplate}" />
  </ClientManagerControls:SizeControlTemplateCollection>

  <DataTemplate DataType="{x:Type Facebook:FacebookContactCollection}">
    <FacebookClient:FriendSummaryControl 
        KeyboardNavigation.IsTabStop="False" 
        FocusVisualStyle="{x:Null}" 
        Templates="{StaticResource FriendSummaryTemplateCollection}" />
  </DataTemplate>

</ClientManagerView:EventResourceDictionary>